/***************************************************************************************
 The copyright in this software is being made available under the BSD License, included
 below. This software may be subject to other third party rights,including patent rights,
 and no such rights are granted under this license.

 Regents of the Tsinghua University, Peking University, Zhejiang University, HKUST
 Tsinghua University, Peking University, Zhejiang University, HKUST 2011

 Copyright (c) 2011, Regents of the Tsinghua University, Peking University, Zhejiang
 University, HKUST. All Rights Reserved.

 Redistribution and use in source and binary forms, with or without modification, are
 permitted provided that the following conditions are met:
   * Redistributions of source code must retain the above copyright notice,
     this list of conditions and the following disclaimer.
   * Redistributions in binary form must reproduce the above copyright notice,
     this list of conditions and the following disclaimer in the documentation
     and/or other materials provided with the distribution.
   * Neither the names of the copyright holders nor the names of its
     contributors may be used to endorse or promote products derived from this
     software without specific prior written permission.

 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 OF SUCH DAMAGE.
***************************************************************************************/

/*
*************************************************************************************
* File name:
* Function:
*
*************************************************************************************
*/

#include "global.h"
#include "defines.h"

#define NUM_2D_TABLES 4
#define CODE2D_ESCAPE_SYMBOL 59

// ========================================================
// external variables
// ========================================================
//extern const int V[QUANT_PERIOD][6];    //!< De-Quantization table
// extern const int DQMAP[4][4];   //!< Mapping the proper de-quantization value for coefficient position
//extern const int N[2];          //!< Dequantization normalization
extern const int SCAN[2][64][2];
extern const unsigned short int cbp_blk_masks[4];
extern const byte QP_SCALE_CR[64];

//VBS
extern const int SCAN_16[2][256][2];
extern const int SCAN_4x4[2][16][2];

extern const char MaxRun[3][7];
extern const char RefAbsLevel[19][26];


void inv_transform_B8( int curr_blk[B8_SIZE][B8_SIZE] );
void get_curr_blk( int block8x8, image_t *img, int curr_blk[B8_SIZE][B8_SIZE] );
void get_curr_blk_16x16( image_t *img, int curr_blk[MB_BLOCK_SIZE][MB_BLOCK_SIZE] );
void idct_dequant_B8( int block8x8, int qp,int curr_blk[B8_SIZE][B8_SIZE], image_t *img );
void idct_dequant_B8inB4( int block8x8, int qp,int curr_blk[B8_SIZE][B8_SIZE], image_t *img );

void read_luma_coeff_b8_qcoder( int block8x8, input_t* inp, image_t* img );
void read_chroma_coeff_b8_qcoder( int block8x8, input_t* inp, image_t* img );

void inv_transform_B16( int curr_blk[16][16] );
void Dequant_B16( int qp, int curr_blk[16][16] );

void Dequant_B4( int qp, int curr_blk[4][4] );
void inv_transform_B4( int curr_blk[B4_SIZE][B4_SIZE] ) ;

void Dequant_B8inB4( int qp,int curr_blk[B8_SIZE][B8_SIZE] );
int inv_transform_B8inB4( int blk[B8_SIZE][B8_SIZE], int block8x8 );

void read_luma_coeff_b4_qcoder( int block8x8, int block4x4, input_t *inp, image_t *img );

